<script setup>
import {onMounted, ref} from 'vue'
import {useRoute} from 'vue-router'
import service from '@/api/request0.js'
import router from "@/router/index.js";

const route = useRoute()
const item = ref({})

const fetchItemDetail = async () => {
  try {
    item.value = await service.get(`/item/${route.params.itemId}`)
  } catch (error) {
    console.error('获取商品项详情失败:', error)
  }
}

onMounted(fetchItemDetail)
</script>

<template>
  <div class="item-detail">
    <h2 class="detail-title">商品项详情</h2>

    <div class="detail-card">
      <div class="item-content">
        <div class="info-column">
          <div class="info-item">
            <label>商品项ID：</label>
            <span class="value">{{ item.itemId }}</span>
          </div>
          <div class="info-item">
            <label>产品ID：</label>
            <span>{{ item.productId }}</span>
          </div>
          <div class="info-item">
            <label>供应商ID：</label>
            <span>{{ item.supplierId }}</span>
          </div>
          <div class="price-item">
            <label>售价：</label>
            <span class="price-tag">¥{{ item.listPrice }}</span>
          </div>
        </div>
        <div class="attributes-column">
          <div class="attribute-box">
            <h3>商品属性</h3>
            <p class="attribute-value">{{ item.attribute1 }}</p>
          </div>
        </div>
      </div>
    </div>
    <button class="action-button back-button" @click="router.go(-1)">← 返回</button>
  </div>
</template>

<style scoped>
.item-info {
  display: flex;
  gap: 30px;
  padding: 20px;
}

.info-column,
.attributes-column {
  flex: 1;
}

.item-detail {
  padding: 20px;
  max-width: 800px;
  margin: 0 auto;
}

.item-info {
  padding: 20px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  background-color: #f9f9f9;
}

.detail-title {
  font-size: 1.8rem;
  color: #2c3e50;
  margin-bottom: 2rem;
}

.detail-card {
  padding: 2rem;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  margin-bottom: 2rem;
}

.price-tag {
  display: inline-block;
  padding: 8px 20px;
  background: linear-gradient(135deg, #42b983 0%, #33a06f 100%);
  color: white;
  border-radius: 20px;
  font-size: 1.4rem;
  font-weight: 600;
  margin-top: 1rem;
}

.attribute-box {
  padding: 1.5rem;
  background: #f8f9fa;
  border-radius: 8px;
  border-left: 4px solid #42b983;
}

.attribute-value {
  font-size: 1.1rem;
  color: #4a5568;
  margin-top: 0.5rem;
}

@media (max-width: 768px) {
  .item-content {
    flex-direction: column;
    gap: 1.5rem;
  }
  .detail-card {
    padding: 1.5rem;
  }
}
</style>